package com.example.enjoyarkuix;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.enjoyarkuix.R;
import com.example.enjoyarkuix.base.BaseActivity;
import com.example.enjoyarkuix.bean.ItemDataBean;
import com.example.enjoyarkuix.common.Constant;
import com.example.enjoyarkuix.adapter.MyItemRecyclerViewAdapter;
import com.example.enjoyarkuix.interfaces.OnItemClickListener;

import java.util.ArrayList;

public class ShowJumpActivity extends BaseActivity {

    private static final String TAG = "DemoDetailActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        initTopBar("");

        ArrayList<ItemDataBean> arrayList = new ArrayList();
        Intent intent = getIntent();
        if (intent == null) {
            return;
        }
//        ItemDataBean itemDataBean = (ItemDataBean) intent.getSerializableExtra("ItemDataBean");
//        int page = itemDataBean.getPage();
//        if (page == Constant.PAGE_MULTI_DEVICE) {
//            ItemDataBean itemDataBean0 = new ItemDataBean("音乐播放器", Constant.JUDPT_ENTRY_ENTRY_ABILITY_ACTIVITY, "musicplayer", "MusicPlayerAbility");
//            ItemDataBean itemDataBean1 = new ItemDataBean("应用市场首页", Constant.JUDPT_ENTRY_ENTRY_ABILITY_ACTIVITY, "appstorefeature", "AppstorefeatureAbility");
//            arrayList.add(itemDataBean0);
//            arrayList.add(itemDataBean1);
//            setTvTopBarTitle("一多");
//        } else if (page == Constant.PAGE_C_CROSSPLATFORM) {
//            ItemDataBean itemDataBean0 = new ItemDataBean("C ~ Helloword", Constant.JUDPT_ENTRY_ENTRY_ABILITY_ACTIVITY, "entry", "EntryAbility");
//            ItemDataBean itemDataBean1 = new ItemDataBean("C ~ OpenCV图片处理", Constant.JUDPT_ANDROID_ACTIVITY, OpencvJumpActivity.class);
//            arrayList.add(itemDataBean0);
//            arrayList.add(itemDataBean1);
//            setTvTopBarTitle(getResources().getString(R.string.title_c_crossplatform));
//        }

        ItemDataBean itemDataBean0 = new ItemDataBean("C ~ Helloword", Constant.JUDPT_ENTRY_ENTRY_ABILITY_ACTIVITY, "napi_helloword", "Napi_hellowordAbility");
        arrayList.add(itemDataBean0);
        setTvTopBarTitle(getResources().getString(R.string.title_c_crossplatform));

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycleview);
        Context context = this;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        MyItemRecyclerViewAdapter myItemRecyclerViewAdapter = new MyItemRecyclerViewAdapter(arrayList);
        recyclerView.setAdapter(myItemRecyclerViewAdapter);

        myItemRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ItemDataBean itemDataBean = arrayList.get(position);
                if (itemDataBean == null) {
                    return;
                }
                int ItemJudgeType = itemDataBean.getItemJudgeType();
                try {
                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("ItemDataBean", itemDataBean);//序列化
                    intent.putExtras(bundle);//发送数据
                    if (ItemJudgeType == Constant.JUDPT_SHOW_ACTIVITY) {
                        intent.setClass(context, ShowJumpActivity.class);
                    } else if (ItemJudgeType == Constant.JUDPT_ENTRY_ENTRY_ABILITY_ACTIVITY) {
                        intent.setClass(context, EntryCommonAbilityActivity.class);
                    } else if (ItemJudgeType == Constant.JUDPT_ANDROID_ACTIVITY) {
                        Class c = itemDataBean.getClz();
                        if (c == null) {
                            return;
                        }
                        intent.setClass(context, c);
                    } else {
                        return;
                    }
                    startActivity(intent);
                } catch (Exception e) {
                    Log.e(TAG, "onItemClick: " + e.toString());
                }
            }
        });

    }
}